#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include "rngs.h"

#define DEBUG 0

void checkGreatHallCard(int p, struct gameState *post, int handPos) {

struct gameState pre;
memcpy (&pre, post, sizeof(struct gameState));
   
int r;
int card = great_hall;

r = cardEffect (card, 0, 0, 0, post, handPos, 0);
drawCard(p, &pre);	
pre.numActions++;
discardCard(handPos, p, &pre, 0);

assert(pre.numActions == post->numActions);
assert(pre.handCount[p] == post->handCount[p]);
assert (r == 0);	
}

int main () {
int i, n, p, handPos;
struct gameState G;
   
printf ("Testing Great Hall.\n");
printf ("RANDOM TESTS.\n");
   
SelectStream(2);
PutSeed(3);
   
for (n = 0; n < 2000; n++) {
for (i = 0; i < sizeof(struct gameState); i++) {
((char*)&G)[i] = floor(Random() * 256);
}
p = floor(Random() * MAX_PLAYERS); 
G.deckCount[p] = floor(Random() * MAX_DECK);
G.discardCount[p] = floor(Random() * MAX_DECK);
G.handCount[p] = floor(Random() * MAX_HAND);
G.playedCardCount = floor(Random() * MAX_DECK);
G.whoseTurn = p;
G.numActions = 1;
handPos = floor(Random() * G.handCount[p]);

for (i = 0; i < G.deckCount[p]; i++) {
G.deck[p][i] = floor(Random() * treasure_map);
}
for (i = 0; i < G.discardCount[p]; i++) {
G.discard[p][i] = floor(Random() * treasure_map);
}
for (i = 0; i < G.handCount[p]; i++) {
G.hand[p][i] = floor(Random() * treasure_map);
}

checkGreatHallCard(p, &G, handPos);	   
}
  
printf ("ALL TESTS OK\n");
   
return 0;
}